<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>GO机网管理后台</title>
	<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge">
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
	<link href="css/nifty.min.css" rel="stylesheet">
	<link href="../../css/demo/nifty-demo-icons.min.css" rel="stylesheet">
	<link href="../../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<link href="../../css/user_defined.css" rel="stylesheet">
	<link href="../../plugins/pace/pace.min.css" rel="stylesheet">
	<script src="../../plugins/pace/pace.min.js?2016/8/5"></script>
	<script src="../../js/jquery-2.2.1.min.js"></script>
</head>

<!--TIPS-->
<!--You may remove all ID or Class names which contain "demo-", they are only used for demonstration. -->

<body id="main">
<div id="container" class="effect mainnav-lg">
	@@include('public/header.html')
	<div class="boxed">
		<div id="content-container">
			<div id="page-title">
				<h1 class="page-header text-overflow">管理员设置</h1>
			</div>
			
			<div id="page-content">
				<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">添加管理员</button>
			</div>
			
			<div class="row mar-top pad-top pad-all">
				<style>
					.mar-top table {
						width:100%;
						color: #999;
						margin:auto;
					}
					
					.mar-top td,.mar-top th{
						padding: 10px;
						border:1px solid #bbbbbb;
						text-align:center;
					}
					.mar-top td{
						cursor:pointer;
					}
					.mar-top tr:hover{
						background:#f0f0f0;
					}
					.mar-top th{
						text-align: center;
						background: #e6e6e6;
					}
					
					select{
						padding:5px;
						margin-right:20px;
					}
				</style>
				 <div class="text-right">
                    <button class="btn btn-primary" v-on:click="page(-1)" v-show="currentPage>0">上一页</button>
                    <button class="btn btn-primary" v-on:click="page(1)">下一页</button>
                </div>
				<table>
					<tr>
						<th width="150">姓名</th>
						<th width="350">账号</th>
						<th width="350">编辑权限</th>
					</tr>
					<tr v-for="p in admins">
						<td><div v-text="p.user_name"></div></td>
						<td><div v-text="p.account"></div></td>
						<td><button class="btn btn-primary" v-on:click="editAdmin(p);">编辑</button></td>
					</tr>
				</table>
			</div>
			<!--End page content-->
		</div>
		
		<nav id="mainnav-container">
			@@include('public/left_menu.html')
		</nav>
	
	</div>
	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h4 class="modal-title">添加管理员</h4>
				</div>
				<div class="modal-body">
					<style>
						table select, table input{
							width:200px;
							margin:15px 0;
							padding:5px;
						}
						.modal-body table td:first-child{
							width:150px;
							text-align:right;
							padding-right:8px;
							font-weight:800;
						}
						td{border:none;}
						label{user-select:none;}
						label span{
							padding:6px;
							margin:5px;
							margin-left:0;
							margin-right:8px;
							display:inline-block;
							border:1px solid #ccc;
						}
						input[type=checkbox]{
							display:none;
						}
						input:checked + span{
							background:#5fa2dd;
							border-color:#5fa2dd;
							color:#fff;
						}
					</style>
					<validator name="validation">
					<table class="form-horizontal">
						<tr>
							<td>姓名 : </td>
							<td>
								<input
										v-model="admin.user_name"
										v-validate:admin.user_name="{required:true}"
										placeholder="姓名"
										autocomplete="off">
							</td>
						</tr>
						<tr>
							<td>登陆账号 : </td>
							<td>
								<input
										type="number"
										v-model="admin.account"
										v-validate:admin.account="{required:true}"
										placeholder="登陆账号"
										autocomplete="off">
							</td>
						</tr>
						<tr>
							<td>登陆密码 : </td>
							<td><input
									type="password"
									v-model="admin.password"
									v-validate:admin.password="{required:true}"
									placeholder="登陆密码"
									autocomplete="off"></td>
						</tr>
					</table>
					</validator>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" v-on:click="addAdmin()" :disabled="!$validation.valid" id="addBrand">确定添加</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
		
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h4 class="modal-title" id="myModalLabel">编辑管理员</h4>
				</div>
				<div class="modal-body">
					<style>
						input[readonly] {
							border:none;
							font-size:18px;
						}
					</style>
					<validator name="validation1">
						<table class="form-horizontal">
							<tr>
								<td>姓名 : </td>
								<td><input value="{{editingAdmin.user_name}}" type="text" readonly></td>
							</tr>
							<tr>
								<td>登陆账号 : </td>
								<td><input value="{{editingAdmin.account}}" type="text" readonly></td>
							</tr>
							<tr>
								<td>访问权限 : </td>
								<td>
									<label v-for="m in menus">
										<input value="{{m.id}}" type="checkbox" v-model="checkMenus">
										<span v-text="m.name"></span>
									</label>
								</td>
							</tr>
						</table>
					</validator>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" v-on:click="saveAdmin()" :disabled="!$validation1.valid">保存</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div>
</div>
@@include('public/footer.html')
<script src="js/vue-validator.min.js"></script>
<script>
var vue = new Vue({
	el: '#main',
	data: {
		"menus":[],
		"checkMenus":[],
		"admin":{},
		"currentPage":1,
		admins:[],
		"editingAdmin":{}
	},
	methods: {
		/*添加城市合伙人*/
		addAdmin:function(){
			var index = layer.load(1, {shade: [0.5,'#555']});
			$.post(apiRecycle+"partner.php?m=Admin&c=Menu&a=add_account", {
				account:vue.admin.account,
				password:vue.admin.password,
				user_name:vue.admin.user_name
			}, function(res){
				if(res.code==200){
					location.reload();
				} else {
					alert(res.message);
				}
				layer.close(index);
			}, "json");
		},
		
		loadAdmin:function(){
			var thiz = this;
			/*获取所有合伙人*/
			var index = layer.load(1, {shade: [0.5,'#555']});
			$.get(apiRecycle+"partner.php?m=Admin&c=Menu&a=get_account", {}, function(res){
				vue.admins = res.data;
				layer.close(index);
			}, "json");
		},
		
		page:function(next){
			var thiz = this;
			thiz.currentPage += parseInt(next);
			if(thiz.currentPage<0){
				thiz.currentPage = 0;
			}
			this.loadAdmin();
		},
		
		editAdmin:function(p){
			vue.editingAdmin = p;
			$("#myModal1").modal("show");
			var index = layer.load(1, {shade: [0.5,'#555']});
			$.get(apiRecycle+"partner.php?m=Admin&c=Menu&a=getMemberMenu", {
				member_id:p.id
			}, function(res){
				vue.checkMenus = [];
				for(var i=0; i<res.data.length; i++){
					if(res.data[i].is_select){
						vue.checkMenus.push(res.data[i].id);
					}
				}
				console.log(vue.checkMenus);
				layer.close(index);
			}, "json");
			
		},
		
		saveAdmin:function(){
			var index = layer.load(1, {shade: [0.5,'#555']});
			$.post(apiRecycle+"partner.php?m=Admin&c=Menu&a=setMenuById", {
				member_id:vue.editingAdmin.id,
				m_id:JSON.stringify(vue.checkMenus)
			}, function(res){
				vue.checkMenus = [];
				vue.editingAdmin = {};
				$("#myModal1").modal("hide");
				layer.close(index);
			}, "json")
		}
	},
	ready: function () {
		var thiz = this;
		/*获取管理员*/
		var index = layer.load(1, {shade: [0.5,'#555']});
		$.get(apiRecycle+"partner.php?m=Admin&c=Menu&a=getMemberMenu", {}, function(res){
			thiz.menus = res.data;
			layer.close(index);
		}, "json");
		
		/*获取所有合伙人*/
		thiz.loadAdmin();
	}
});
</script>
</body>
</html>
